package test.jvm;
/**
 *
 * 虚拟机栈溢出测试，使用-Xss 参数减少栈内存容量
 * VM Args : -Xss128k
 * 运行结果：
 * stack length:993
 * Exception in thread "main" java.lang.StackOverflowError
 * @author zzq
 * @datetime 2025-01-01 15:54
 */
public class StackOOM {

	private int slength = 1;
	//栈泄露
	public void stackLeak() {

		slength++;
		stackLeak();
	}
	public static void main(String[] args) {
		StackOOM oom = new StackOOM();
		try {
			oom.stackLeak();

		} catch (Throwable e) {
			System.out.println("stack length:" + oom.slength);
			throw e;
		}
	}
}
